package com.cloud.code.dynaproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Arrays;

public class ShopProxy implements InvocationHandler {

    private Object object;

    //Proxy为动态代理类
    public Object newProxyInstance(Object object){
        this.object = object;
        return Proxy.newProxyInstance(object.getClass().getClassLoader(),object.getClass().getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("start -->> " +method.getName());

        Arrays.stream(args).forEach(System.out::println);

        Object invoke = method.invoke(object, args);

        System.out.println("end -->> " +method.getName());
        return invoke;
    }
}
